<!-- 注册
 1. vue始终在用双向绑定的思想来准备前后端交互，每一个vue都会定义好变量给 表单（form）或者表格（table）中的html元素的值绑定
-->
<template>
  <div><!-- element组件库的Dialog对话框默认可以通过点击 modal 关闭 Dialog，即点击空白处弹框可关闭。 -->
    <!-- :visible.sync 子组键改变父组件的值 控制子组件的显示-->
    <el-dialog title="标题名" :visible.sync="addDialogIsShow" :before-close="handleClose" :close-on-click-modal="false">
    <el-form  :model="team" label-width="80px" :rules="addTeamRules" ref="addTeamForm">
       <el-form-item label="球队名称" prop="name">
         <el-col :span="8">
          <el-input v-model="team.name"></el-input>
         </el-col></el-form-item>
       <el-form-item label="球队队徽">
         <el-col :span="18">
         <el-input v-model="team.pic"></el-input>
         </el-col>
       </el-form-item>
    </el-form>
    <span>
      <el-button type="success" @click="addTeam('addTeamForm')">注册</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import rules from "../../../../static/js/validator/rules.js"
    export default {
      name: "addTeam",
      data(){
        return {team:{name:"",pic:""},
          addDialogIsShow: false,
          addTeamRules:{name:[{required:true,message:"球队名称不能为空",trigger:'blur'},
              {max:20,min:2,message:'长度异常 长度在2-20之间',trigger:'blur'},{pattern:/^[\u0391-\uFFE5A-Za-z]+$/,message:'球队名称必须为中文',trigger:'blur'}]}
        }
      },
      methods: {
        addTeam:function(addTeamForm){
          this.$refs[addTeamForm].validate(valid => {//此处refs对象和标签上的ref对应
            if (valid) {
              //如果通过验证 to do...
              console.log(this.team);
              //alert(this.$store.state.host);
              alert(this.team.name+"添加成功");
              this.handleClose();
            } else {
              console.log('error submit!!')
              return false
            }
          })},
        //页面初始化时加载的事件
        init() {
          this.addDialogIsShow = true;
        },

        //关闭页面
        handleClose() {
          this.addDialogIsShow = false;
          //给父组件传参
          this.$emit("addDialogIsShow", this.addDialogIsShow);
        }
      },

      //监听
      watch: {
        dialogisShow(newValue, oldValue) {
          this.addDialogIsShow = newValue;
        }
      }

      }
</script>

<style scoped>

</style>
